package com.ssh.controller.repair;

import com.ssh.service.RepairService;
import com.common.tool.Message;
import com.common.tool.Page;
import com.common.tool.PagingTool;
import com.ssh.controller.base.BaseController;
import com.ssh.entity.Repair;
import com.ssh.entity.User;
import com.ssh.requestPackage.RepairRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 文 件 名 称：repairController.
 * 文 件 说 明：
 * 创   建   人：zpen.
 * 创 建 时 间：2018/3/2 10:58.
 */
@Controller
@RequestMapping(value = "repair.action")
public class RepairController extends BaseController {
    @Autowired
    RepairService repairService;

    @RequestMapping(params = "method=goRepair")
    public String goRepair(){
        return "repair/repair";
    }

    @RequestMapping(params = "method=saveRepair")
    public Message saveRepair(HttpSession session,Repair repair)throws Exception {
        Message message = new Message();
        User user = (User) session.getAttribute("user");
        Long faly =  repairService.save(repair,user);
        if(faly>0){
            message.setSuccess("success");
            message.setMsg("订单创建成功！");
        }else {
            message.setSuccess("fail");
            message.setMsg("创建订单的过程中出现未知错误，请联系管理员进行排查！");
        }
        return message;
    }

    @RequestMapping(params = "method=getDate")
    @ResponseBody
    public PagingTool getRepair(RepairRequest repairRequest,Page page){
        PagingTool pagingTool = repairService.queryForPage(repairRequest,page);
        return pagingTool;

    }
    @RequestMapping(params = "method=create")
    public String create(){
        return "repair/create";
    }
}
